public class Solution {
    public static int [] twoSum(int[] nums, int target){
        int result[]=new int[2];
        for(int i=0;i<nums.length-1;i++){
            for(int j=i+1;j<nums.length;j++){
                if(nums[i]+nums[j]==target){
                    result[0]=i;
                    result[1]=j;
                }
            }
        }
        return result;
    }
    public static int reverse(int x) {
        long r=0;
        while (x!=0){
            r=r*10+x%10;
            x=x/10;
        }
        if(r>2147483647||r<-2147483648){
            r=0;
        }
        return (int)r;
    }

    public static boolean isPalindrome(int x) {
        String s=String.valueOf(x);
        int i=0;
        if(x<0){
            i=1;
        }
        int l=s.length()-1;
        while (i<=l){
            if(s.charAt(i)!=s.charAt(l)){
                return false;
            }
            i++;l--;
        }
        return true;
    }

    public static ListNode addTwoNumbers(ListNode l1, ListNode l2) {
        ListNode result;
        int c=0;
        int temp;
        temp=l1.val+l2.val;
        if(temp>=10){
            c=1;
            temp=temp%10;
        }
        result=new ListNode(temp);
        ListNode p=result;
        while (l1.next!=null||l2.next!=null){
            int a1,a2;
            if(l1.next==null){
                a1=0;
                l2=l2.next;
                a2=l2.val;
            }else if(l2.next==null){
                a2=0;
                l1=l1.next;
                a1=l1.val;
            }else {
                l1=l1.next;
                l2=l2.next;
                a1=l1.val;
                a2=l2.val;

            }
            int t=a1+a2+c;
            if(t>=10){
                c=1;
                t=t%10;
            }else {
                c=0;
            }
            ListNode next=new ListNode(t);
            p.next=next;
            p=p.next;
        }
        if(c==1){
            p.next=new ListNode(1);
        }
        return result;
    }

    public static int lengthOfLongestSubstring(String s) {
        int temp=0;int j;
        for(int i=0;i<s.length();i++){
            for(j=i+1;j<s.length();j++){
                String str=s.substring(i,j);
                if(str.indexOf(s.charAt(j))==-1)
                    continue;
                else break;
            }
            if(j-i>temp)temp=j-i;
        }
        return temp;
    }

    public static String longestPalindrome(String s) {
        int len=s.length();
        int dis=0,j;
        String result=s.substring(0,1);
        String temp=result;
        for(int i=0;i<len-1;i++){
            for (j=len;j>i;j--){
                temp=s.substring(i,j);
                StringBuffer str=new StringBuffer(temp).reverse();
                if(str.toString().equals(temp)){
                    break;
                }
            }
            if(j-i>dis){
                dis=j-i;
                result=temp;
            }
        }
        return result;
    }
}
